package org.foxas.ui
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	
	import org.foxas.base.FFunc;
	import org.foxas.base.FGeom;
	
	public final class FUI
	{
//		public static var root:DisplayObjectContainer;
		private static var bg:Sprite = new Sprite();
		public static var stage:Sprite = new Sprite();
		public static function init(_container:DisplayObjectContainer):void{
//			root = _container;
			_container.addChild(stage);
			stage.addEventListener(Event.ADDED_TO_STAGE,onAddStage);
		}
		public static function onAddStage(_e:Event):void{
			stage.removeEventListener(Event.ADDED_TO_STAGE,onAddStage);
			FGeom.DrawRect(bg,0,0,stage.stage.stageWidth,stage.stage.stageHeight,0x999999,0.4);
			stage.addChild(bg);
			bg.visible = false;
		}
		public static function addChild(_child:DisplayObject,_exclusive:Boolean=true):void{
			FFunc.lvTop(stage);
			stage.addChild(_child);
			bg.visible = _exclusive;
			_child.x = (stage.stage.stageWidth-_child.width)/2;
			_child.y = (stage.stage.stageHeight-_child.height)/2;
		}
		public static function removeChild(_child:DisplayObject):void{
			if(stage.contains(_child)){
				stage.removeChild(_child);
			}
			if(stage.numChildren==1){
				bg.visible = false;
			}
		}
	}
}